package com.bootdo.blog.dao;

import com.bootdo.blog.domain.InspectionDO;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
/**
 * 
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2021-03-07 10:38:32
 */
@Mapper
public interface InspectionMapper {

	@Select("select `inspection_id`, `order`, `inspection_time`, `varieties`, `result`, `third_party`, `principal`, `telephone`, `flag` from tb_inspection where inspection_id = #{id}")
	InspectionDO get(Integer inspectionId);
	
	@Select("<script>" +
	"select * from tb_inspection " + 
			"<where>" + 
		  		  "<if test=\"inspectionId != null and inspectionId != ''\">"+ "and inspection_id = #{inspectionId} " + "</if>" + 
		  		  "<if test=\"order != null and order != ''\">"+ "and order = #{order} " + "</if>" + 
		  		  "<if test=\"inspectionTime != null and inspectionTime != ''\">"+ "and inspection_time = #{inspectionTime} " + "</if>" + 
		  		  "<if test=\"varieties != null and varieties != ''\">"+ "and varieties = #{varieties} " + "</if>" + 
		  		  "<if test=\"result != null and result != ''\">"+ "and result = #{result} " + "</if>" + 
		  		  "<if test=\"thirdParty != null and thirdParty != ''\">"+ "and third_party = #{thirdParty} " + "</if>" + 
		  		  "<if test=\"principal != null and principal != ''\">"+ "and principal = #{principal} " + "</if>" + 
		  		  "<if test=\"telephone != null and telephone != ''\">"+ "and telephone = #{telephone} " + "</if>" + 
		  		  "<if test=\"flag != null and flag != ''\">"+ "and flag = #{flag} " + "</if>" + 
		  			"</where>"+ 
			" <choose>" + 
	            "<when test=\"sort != null and sort.trim() != ''\">" + 
	                "order by ${sort} ${order}" + 
	            "</when>" + 
				"<otherwise>" + 
	                "order by inspection_id desc" + 
				"</otherwise>" + 
	        "</choose>"+
			"<if test=\"offset != null and limit != null\">"+
			"limit #{offset}, #{limit}" + 
			"</if>"+
			"</script>")
	List<InspectionDO> list(Map<String, Object> map);
	
	@Select("<script>" +
	"select count(*) from tb_inspection " + 
			"<where>" + 
		  		  "<if test=\"inspectionId != null and inspectionId != ''\">"+ "and inspection_id = #{inspectionId} " + "</if>" + 
		  		  "<if test=\"order != null and order != ''\">"+ "and order = #{order} " + "</if>" + 
		  		  "<if test=\"inspectionTime != null and inspectionTime != ''\">"+ "and inspection_time = #{inspectionTime} " + "</if>" + 
		  		  "<if test=\"varieties != null and varieties != ''\">"+ "and varieties = #{varieties} " + "</if>" + 
		  		  "<if test=\"result != null and result != ''\">"+ "and result = #{result} " + "</if>" + 
		  		  "<if test=\"thirdParty != null and thirdParty != ''\">"+ "and third_party = #{thirdParty} " + "</if>" + 
		  		  "<if test=\"principal != null and principal != ''\">"+ "and principal = #{principal} " + "</if>" + 
		  		  "<if test=\"telephone != null and telephone != ''\">"+ "and telephone = #{telephone} " + "</if>" + 
		  		  "<if test=\"flag != null and flag != ''\">"+ "and flag = #{flag} " + "</if>" + 
		  			"</where>"+ 
			"</script>")
	int count(Map<String, Object> map);
	
	@Insert("insert into tb_inspection (`order`, `inspection_time`, `varieties`, `result`, `third_party`, `principal`, `telephone`, `flag`)"
	+ "values (#{order}, #{inspectionTime}, #{varieties}, #{result}, #{thirdParty}, #{principal}, #{telephone}, #{flag})")
	int save(InspectionDO inspection);
	
	@Update("<script>"+ 
			"update tb_inspection " + 
					"<set>" + 
		            "<if test=\"inspectionId != null\">`inspection_id` = #{inspectionId}, </if>" + 
                    "<if test=\"order != null\">`order` = #{order}, </if>" + 
                    "<if test=\"inspectionTime != null\">`inspection_time` = #{inspectionTime}, </if>" + 
                    "<if test=\"varieties != null\">`varieties` = #{varieties}, </if>" + 
                    "<if test=\"result != null\">`result` = #{result}, </if>" + 
                    "<if test=\"thirdParty != null\">`third_party` = #{thirdParty}, </if>" + 
                    "<if test=\"principal != null\">`principal` = #{principal}, </if>" + 
                    "<if test=\"telephone != null\">`telephone` = #{telephone}, </if>" + 
                    "<if test=\"flag != null\">`flag` = #{flag}, </if>" + 
          					"</set>" + 
					"where inspection_id = #{inspectionId}"+
			"</script>")
	int update(InspectionDO inspection);
	
	@Delete("delete from tb_inspection where inspection_id =#{inspectionId}")
	int remove(Integer inspection_id);
	
	@Delete("<script>"+ 
			"delete from tb_inspection where inspection_id in " + 
					"<foreach item=\"inspectionId\" collection=\"array\" open=\"(\" separator=\",\" close=\")\">" + 
						"#{inspectionId}" + 
					"</foreach>"+
			"</script>")
	int batchRemove(Integer[] inspectionIds);
}
